import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== private component
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		forms : [
			{ label: '条码号',		name: 'barcode'},
			{ label: '操作人',		name: 'operator_id',				type:'select', 		loading:true,	hide: !this.props.all },
			{ label: '生成时间',		names: ['start_date','end_date'], 	type:'date-range', 	loading:true },
		],
	}
	model = {}
	
	componentDidMount(){
		this.getSelect()
		this.fetch()	
	}
	
	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		$cache.then( async f => {
			// 操作人
			$fn.setRow( forms, 'operator_id', await f.getCache({ api:'employee' }) )
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'sp-barcode-log/index', {param: {all: !this.props.all ? '' : 1 }} )
	
	// 表单
	cols = [
		{ title: '开始条码', 	dataIndex: 'start_code',	...$fn.table.spec_code },
		{ title: '结束条码', 	dataIndex: 'end_code',		...$fn.table.spec_code },
		{ title: '数量', 		dataIndex: 'create_num',	...$fn.table.num },
		{ title: '操作人', 		dataIndex: 'real_name',		...$fn.table.name },
		{ title: '医院名称', 	dataIndex: 'hosp_name',		width:200},
		{ title: '操作时间', 	dataIndex: 'created_at',	...$fn.table.time },
	]
	
	render(){
		return (
			<>
				{/* 搜索 */}
				{ SearchForm.call(this) }
				{/* 表格 */}
				{ Table.call(this, { idStr:'end_code' } ) }
			</>
		)
	}
}

export default Index